<template>
	<view>
		<view class="user">
			<image :src="head" mode="" class="head"></image>
			<view class="name">
				<navigator :url="login" hover-class="none"><text>{{name}}</text></navigator>
				<view class="paoshou">
					<image :src="ride" mode="" class="ride"></image>
					<text>跑手</text>
				</view>
			</view>
		</view>

		<view>
			<view class="info" v-for="item in catalog" :key="item.id" @click="navigation(item.id)">
				<image class="icon-img" :src="item.image" :class="item.id == 2 ? 'imgwh':''" mode=""></image>
				<view class="info_item">{{item.name}}</view>
				<view class="flex-1"></view>
				<view class="iconfont icon-jiantou"></view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				head: '../../static/temp/head1.png',
				name: '点击注册登录',
				ride: '../../static/temp/Riding.png',
				catalog: [{
						"id": 1,
						"image": '/static/icon/orders-icon.png',
						"name": '我的接单',
						"path": '../../pagesD/my_order/my_order'
					},
					{
						"id": 2,
						"image": '/static/temp/Riding.png',
						"name": '注册跑手',
						"path": '../../pagesE/Registered_runner/Registered_runner'
					},
					{
						"id": 3,
						"image": '/static/icon/address-icon.png',
						"name": '常用地址',
						"path": '../../pagesB/common_address/common_address'
					},
					{
						"id": 4,
						"image": '/static/icon/help-icon.png',
						"name": '帮助反馈',
						"path": '../../pagesC/Help_feedback/Help_feedback'
					},
					{
						"id": 5,
						"image": '/static/icon/seting-icon.png ',
						"name": '设置',
						"path": '../../pagesF/Set_up/Set_up'
					},
					{
						"id": 6,
						"image": '/static/icon/game-icon.png ',
						"name": '娱乐时刻',
						"path": '../../pagesC/game/game'
					}
				],
				User: {},
				login: '../../pagesD/login_register/login_register',
				if_register: 0
			}
		},
		methods: {
			navigation(index) {
				// if ((JSON.stringify(this.User)) == '{}') {
				// 	uni.showToast({
				// 		title: '你还未登录哦',
				// 		icon:'none'
				// 	})
				// 	return;
				// }
				
				
				if (this.if_register == 0) {
					let if_personal = 1;
					for (let i = 0; i < this.catalog.length; i++) {
						if (this.catalog[i].id === index) {
							if (this.catalog[i].id === 2 && this.User.message.if_runner == 1) {
								uni.showToast({
									title: '您已经是跑手了哦'
								})
								return;
							}
							if(this.User.message!=undefined){
								uni.navigateTo({
									url: `${this.catalog[i].path}?number=${this.User.message.student_number}&if_personal=${if_personal}&if_runner=${this.User.message.if_runner}&Int_name=${this.User.message.Net_name}`
								})
							}
						}
					}
				} else {
					let if_personal = 1;
					for (let i = 0; i < this.catalog.length; i++) {
						if (this.catalog[i].id === index) {
							if (this.catalog[i].id === 2 && this.User.if_runner == 1) {
								uni.showToast({
									title: '您已经是跑手了哦'
								})
								return;
							}
							uni.navigateTo({
								url: `${this.catalog[i].path}?number=${this.User.student_number}&if_personal=${if_personal}&if_runner=${this.User.if_runner}&Int_name=${this.User.Net_name}`
							})
						}
					}
				}
			}
		},
		onLoad() {
			// uni.$on('give_UserMessage', (data) => {
			// 	this.User = data;
			// 	this.name = this.User.message.Net_name;
				let if_personal = 1;
			// 	this.login =
			// 		`../../pagesE/personal_info/personal_info?number=${this.User.message.student_number}&if_personal=${if_personal}&if_runner=${this.User.message.if_runner}&Int_name=${this.User.message.Net_name}`;
			// 	if (this.User.message.if_runner == 1) {
			// 		this.ride = '../../static/temp/Riding_red.png'
			// 	}
			// })

			// uni.$on('give_reivse_UserMessage', (data) => {
			// 	this.User = data;
			// 	this.if_register = 1;
			// 	let if_personal = 1;
			// 	this.login =
			// 		`../../pagesE/personal_info/personal_info?number=${this.User.student_number}&if_personal=${if_personal}&if_runner=${this.User.if_runner}&Int_name=${this.User.Net_name}`;
			// 	if (this.User.if_runner == 1) {
			// 		this.ride = '../../static/temp/Riding_red.png'
			// 	}
			// })

			// uni.$on('Sgin_Out', () => {
			// 	this.User = {};
			// 	this.name = '用户昵称(点击注册登录)';
			// 	this.ride = '../../static/temp/Riding.png';
			// 	this.login = '../../pagesD/login_register/login_register';

			// 	getApp().globalData.User = {};
			// })


			uni.$on('revise_name', (data) => {
				this.name = data;
			})
		},
		onReady() {
			console.log("this is the on ready life")
		},
		onShow(){
			console.log("this is the on show view");
			let if_personal = 1;
			this.User= JSON.parse(uni.getStorageSync('userInfo') || '{}') ;
			console.log(this.User,'this is User');
			if ((JSON.stringify(this.User.message)) == '{}' || this.User === undefined) {
				uni.showToast({
					title: '你还未登录哦',
					icon:'none'
				})
				this.name = '用户昵称(点击注册登录)';
				this.ride = '../../static/temp/Riding.png';
				this.head = '../../static/temp/head1.png';
				this.login = '../../pagesD/login_register/login_register';
				return;
			}else{
				console.log('y');
				console.log(this.User.message,'this is true');
				console.log(this.User.message != undefined,'this is true');
				if (this.User.message != undefined && this.User.message.if_runner == 1) {
					this.ride = '../../static/temp/Riding_red.png'
				}
				let {message} = this.User;
				if(message != undefined ){
					this.name = message.Net_name;
					this.head = message.image_url;
					this.login =
						`../../pagesE/personal_info/personal_info?number=${this.User.student_number}&if_personal=${if_personal}&if_runner=${this.User.if_runner}&Int_name=${this.User.Net_name}`;
				}
			}
			uni.$on('Sgin_Out', () => {
				this.User= JSON.parse(uni.getStorageSync('userInfo') || '{}') ;
				this.name = '用户昵称(点击注册登录)';
				this.ride = '../../static/temp/Riding.png';
				this.login = '../../pagesD/login_register/login_register';
			    this.head = '../../static/temp/head1.png';
			})
			
			console.log("----------------------");
			console.log(this.name);
		}
	}
</script>

<style lang="scss">
	.flex-1 {
		flex: 1;
	}

	.user {
		display: flex;
		width: 750rpx;
		flex-wrap: wrap;
		padding: 20rpx 0;
		border-bottom: 1px solid #C0C0C0;
		background: #eee;
		// border-radius: 30rpx;

		.head {
			width: 200rpx;
			height: 200rpx;
			border-radius: 100%;
			margin-left: 20rpx;
		}

		.name {
			width: 440rpx;

			text:nth-child(1) {
				display: block;
				margin-left: 20rpx;
				margin-top: 20rpx;
				padding: 20rpx;
			}

			.ride {
				width: 50rpx;
				height: 50rpx;
				margin-left: 20rpx;
			}

			.paoshou {
				display: flex;
				padding: 0 20rpx;

				text {
					display: block;
				}
			}

			navigator {
				height: 100rpx;
				// border: 1px solid #eee;
				line-height: 30rpx;
				font-size: 35rpx;
				font-weight: bold;
				// border-radius: 50rpx;
			}

			.navigator {
				background: #C0C0C0;
				height: 100rpx;
				// border-radius: 50rpx;
			}
		}
	}


	.info {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		border: 1px solid red;
		padding: 25rpx;

		view {
			font-size: 32rpx;
			line-height: 50rpx;
		}

		.icon-img {
			width: 40rpx;
			height: 40rpx;
			margin-right: 20rpx;
		}

		.imgwh {
			width: 44rpx;
			height: 44rpx;
		}

		border: 1px solid #eee;

		.info_item {
			color: #808080;
		}
	}
</style>
